#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ = "__Jack__"


from django import forms
from django.contrib.auth.models import User
from rest_framework import serializers

from .models import Collect, province


class CollectForm(forms.ModelForm):
    class Meta:
        model = Collect
        fields = ('name', 'type', 'location', 'province')


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'


class CollectSerializer(serializers.ModelSerializer):
    # area = serializers.CharField(source='name')
    # value = serializers.IntegerField(source='value')

    class Meta:
        model = Collect  # 写法和上面的CourseForm类似
        # exclude = ('id', )  # 注意元组中只有1个元素时不能写成("id")
        # fields = ('id', 'name', 'introduction', 'teacher', 'price', 'created_at', 'updated_at')
        fields = ('name', 'value')
# class CourseSerializer(serializers.HyperlinkedModelSerializer):
#     teacher = serializers.ReadOnlyField(source='teacher.username')
#
#     class Meta:
#         model = Course
#         # url是默认值，可在settings.py中设置URL_FIELD_NAME使全局生效
#         fields = ('id', 'url', 'name', 'introduction', 'teacher', 'price', 'created_at', 'updated_at')


class MessageSerializer(serializers.ModelSerializer):

    class Meta:
        model = province  # 写法和上面的CourseForm类似
        fields = ('name', 'value')